/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package rcpsp;

import GUI.GanttDiagram;
import data.Data;
import java.util.ArrayList;
import org.jfree.ui.RefineryUtilities;

/**
 *
 * @author Guillaume
 */
public class Solution {
    private ArrayList<Integer> sol;
    private int objSol;
    private long timeToSolve;

    public Solution(ArrayList<Integer> sol, int objSol, long timeToSolve) {
        this.sol = new ArrayList<>(sol);
        this.objSol = objSol;
        this.timeToSolve = timeToSolve;
    }
    
    /**
     * Retourne la durée qu'il a fallu pour trouver la solution.
     * @return la durée qu'il a fallu pour trouver la solution.
     */
    public long getTimeToSolve() {
        return timeToSolve;
    }
    
    /**
     * Returns the start time of jobs in the optimal solution found.
     * 
     * @return the start time of jobs in the optimal solution found.
     */
    public ArrayList<Integer> getSol(){
        return sol;
    }
    
    /**
     * Returns makespan (objective) of the optimal solution found.
     * 
     * @return makespan (objective) of the optimal solution found.
     */
    public int getObjSol(){
        return objSol;
    }
    
    /**
     * displays a gantt's diagram from processTime of jobs (in data) and starts time
     * for them (in this Solution).
     * 
     * this diagram shows start time and end time of each job 
     * in the optimal solution found.
     * 
     * It is important to be sure that this solution correspond to the data passed
     * in argument, unless the display could be wrong or fails.
     * 
     * 
     * @param data the data from which this solution has be found.
     */
    public void displayGanttDiagram(Data data){
        GanttDiagram gantt = new GanttDiagram("", data.getJobs(), sol);
        gantt.pack();
        RefineryUtilities.centerFrameOnScreen(gantt);
        gantt.setVisible(true);
    }
    
    /**
     * Displays starts time of each job in this solution.
     */
    public void displayS(){
        System.out.println("Starts time of jobs :");
        for (int i = 0; i < this.getSol().size(); i++) {
             System.out.println("S" +i+ " = " + sol.get(i));
        }
        System.out.println("");
    }
}
